#include "widget.h"
#include "ui_widget.h"

#include <QPushButton>
#include <QRadioButton>
#include <QButtonGroup>
#include <QLabel>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    /*
    QPushButton* btn=new QPushButton(this);
    QIcon Icon(":/apple.png"); // 创建图形文件
    btn->setIcon(Icon); // 设置图标到按钮上
    btn->setIconSize(QSize(50,50)); // 设置按钮图标大小
    btn->move(200,200); // 移动按钮图标位置
    */

    /*
    QRadioButton* rtn1=new QRadioButton(this);
    rtn1->move(150,150);
    rtn1->setText("男");

    QRadioButton* rtn2=new QRadioButton(this);
    rtn2->move(200,150);
    rtn2->setText("女");

    QLabel* label=new QLabel(this);
    label->resize(100, 15);
    label->move(150,120);

    connect(rtn1,&QPushButton::clicked,this,[=](){
        qDebug()<<"用户选择男";
        label->setText("你选了男");
    });

    connect(rtn2,&QPushButton::clicked,this,[=](){
        qDebug()<<"用户选择女";
        label->setText("你选了女");
    });

    rtn1->setChecked(true); // 设置默认选中

    rtn1->setEnabled(false); // 设置禁用状态
    */

    /*
    // 创建三个 QButtonGroup
    QButtonGroup* group1 = new QButtonGroup(this);
    QButtonGroup* group2 = new QButtonGroup(this);
    QButtonGroup* group3 = new QButtonGroup(this);

    // 给QRadioButton进行分组
    group1->addButton(ui->radioButton);
    group1->addButton(ui->radioButton_2);

    group2->addButton(ui->radioButton_3);
    group2->addButton(ui->radioButton_4);
    group2->addButton(ui->radioButton_5);

    group3->addButton(ui->radioButton_6);
    group3->addButton(ui->radioButton_7);
    */

    connect(ui->pushButton_2,&QPushButton::clicked,this,[=](){
        QString result;
        if (ui->checkBox_4->isChecked())
        {
            result += ui->checkBox_4->text();
        }
        if (ui->checkBox_5->isChecked())
        {
            result += ui->checkBox_5->text();
        }
        if (ui->checkBox_6->isChecked())
        {
            result += ui->checkBox_6->text();
        }
        qDebug() << "用户爱好为: " << result;
    });
}

Widget::~Widget()
{
    delete ui;
}
